// 首页相关api
import request from '@/utils/request'
import { getToken } from '@/utils/token'

// 获取用户已选频道列表
export const getUserChannelListApi = () => {
  return request({
    url: '/v1_0/user/channels',
    headers: {
      Authorization: `Bearer ${getToken()}`
    }
  })
}
// 获取文章列表
// 字段值为undefined是，会使用默认参数值，如果为null，则
export const getArticleListApi = ({ channel_id, timestamp }) => {
  return request({
    url: '/v1_0/articles',
    headers: {
      Authorization: `Bearer ${getToken()}`
    },
    params: {
      channel_id,
      timestamp
    }
  })
}

// 获取所有频道列表
export const getAllChannelListApi = () => {
  return request({
    url: '/v1_0/channels'
  })
}
// 重置频道列表(全部覆盖)
export const setUserChannelListApi = (channelArr) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channelArr // 数组套对象的形式转成json字符串的格式发给后台
    }
  })
}

// 删除指定频道
export const removeChannelListApi = (channelId) => {
  return request({
    url: `/v1_0/user/channels/${channelId}`,
    method: 'DELETE'
  })
}
